﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace English_v2
{
    public partial class MainForm : Form
    {
        private FlagForm flagWindow;

        private bool orFormIsQuest = false;

        public bool OrFormIsQuest
        {
            get
            {
                return this.orFormIsQuest;
            }
            set
            {
                this.orFormIsQuest = value;
            }
        }

        public MainForm()
        {
            InitializeComponent();           
        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            this.timer.Enabled = true;
            this.flagWindow = new FlagForm(); 
            this.flagWindow.ShowDialog();
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this.timer.Enabled = false;
            if (!this.ShowInTaskbar)               //
            {                                      //
                this.flagWindow.Close();                // zatvorenie uvodneho 
                this.ShowInTaskbar = true;         // zobrazenie hlavneho okna aplikacie
                this.Activate();                   //
            }                                      //

            if (this.Opacity < 100)                       //
            {                                             //
                this.Opacity = this.Opacity + 0.01;       // opakovane volanie udalosti timer_Tick
                this.timer.Interval = 15;                 // zakazdym prida 1% viditelnosti a pocka 30 ms
                this.timer.Enabled = true;                //
            }                                             //
        }

        private void setResolutionLabelTrue(object sender, EventArgs e)
        {
            this.resolutionLabel.Text= this.Width.ToString() + " x " + this.Height.ToString();
            this.resolutionLabel.Visible = true;
        }

        private void setResolutionLabelFalse(object sender, EventArgs e)
        {
            this.resolutionLabel.Visible = false;
        }

        private void mouseMove(object sender, EventArgs e)
        {
            string path = ((string)(((PictureBox)sender).Tag)) + ".png";
            ((PictureBox)(sender)).ImageLocation = path;
            this.setStatusBarTextTrue("Click to Start selected App...");
        }

        private void setStatusBarTextTrue(string text)
        {
            this.startText.Text = text;
            this.startText.Visible = true;
        }

        private void mouseLeave(object sender, EventArgs e)
        {
            string path = ((string)(((PictureBox)sender).Tag)) + "_inactive.png";
            ((PictureBox)(sender)).ImageLocation = path;
            this.startText.Visible = false;
        }

        private void startWordsForm(object sender, EventArgs e)
        {
            WordsConForm wordsForm;
            wordsForm = new WordsConForm() { DialogResult = DialogResult.Abort };
            DialogResult result= wordsForm.ShowDialog();
            if (result == DialogResult.Retry)
            {
                this.startWordsForm(sender, e);
            }
        }

        private void startSentenceForm(object sender, EventArgs e)
        {
            SentenceOrForm sentenceForm;
            sentenceForm = new SentenceOrForm() { IsQuest = this.orFormIsQuest };
            sentenceForm.ShowDialog();
            this.checkRestart(sentenceForm.DialogResult, sentenceForm, e);
        }

        private void checkRestart(System.Windows.Forms.DialogResult dialogResult, object sender, EventArgs e)
        {
            switch (dialogResult)
            {
                case DialogResult.No:
                    this.orFormIsQuest = false;
                    this.startSentenceForm(sender, e);
                    break;
                case DialogResult.Yes:
                    this.orFormIsQuest = true;
                    this.startSentenceForm(sender, e);
                    break;
                default:
                    break;
            }
        }

        private void showWordsTutorials(object sender, EventArgs e)
        {
            this.showTutorial(1);
        }

        private void showOrderingTutorials(object sender, EventArgs e)
        {
            this.showTutorial(2);
        }

        private void showGeneralTutorials(object sender, EventArgs e)
        {
            this.showTutorial(0);
        }

        private void showTutorial(int page)
        {
            TutorialForm wcForm;
            wcForm = new TutorialForm() { Page = page };
            wcForm.ShowDialog();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void showAbout(object sender, EventArgs e)
        {
            About aboutForm;
            aboutForm = new About();
            aboutForm.ShowDialog();
        }

        //osetrenie poctu poloziek a akcii itemov v kontextovom menu
        private void picContextMenu_Opened(object sender, EventArgs e)
        {
            PictureBox pb = (PictureBox)this.picContextMenu.SourceControl;
            switch (pb.Name)
            {
                case "orderingPicture":
                    this.initContext(new System.EventHandler(this.startSentenceForm), new System.EventHandler(this.showOrderingTutorials));
                    break;
                case "wordsPicture":
                    this.initContext(new System.EventHandler(this.startWordsForm), new System.EventHandler(this.showWordsTutorials));
                    break;
                case "tutorialPicture":
                    this.initContext(new System.EventHandler(this.showGeneralTutorials));
                    break;
                case "aboutPicture":
                    this.initContext(new System.EventHandler(this.showAbout));
                    break;
                default:
                    return;
            }
        }

        private void initContext(System.EventHandler method, System.EventHandler tutorial)
        {
            this.picContextMenu.Items.Clear();
            this.picContextMenu.Items.Add("Start");
            this.picContextMenu.Items.Add("Show Tutorials");
            this.picContextMenu.Items[0].Click += method;
            this.picContextMenu.Items[1].Click += tutorial;
        }

        private void initContext(System.EventHandler method)
        {
            this.picContextMenu.Items.Clear();
            this.picContextMenu.Items.Add("Show");
            this.picContextMenu.Items[0].Click += method;
        }


   
 
    }
}
